<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


<script>
    //封装优先级队列
    function PriorityQueue(){
        //又封装一个类
        function QueueElement(Element,priority){
            this.emelent = element;
            this.priority = priority;
        }
        //封装属性
        //items的元素是QueueElement的实例

        this.items = [];

        //实现插入方法
        PriorityQueue.prototype.enqueue = function (element,priority){

            var queueElement = new QueueElement(element,priority);

            if(this.items.length === 0){
                this.items.push(queueElement);
            }else{
                var added = false;
                for(var i = 0;i < this.items.length;i++){
                    if(queueElement.priority <this.items[i].priority){
                        this.items.splice(i,0,queueElement);
                        added = true;
                        break;
                    }
                }
                if(!added){
                    this.items.push(queueElement)
                }


            }



        }


    }

    //测试
    var pq = new PriorityQueue();

</script>
</body>
</html>